package com.sgcc.ln.pmos.e_ln_home.presenter;

import com.alibaba.android.arouter.utils.TextUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.sgcc.ln.pmos.common.base.BasePresenter;
import com.sgcc.ln.pmos.common.http.HttpInterConst;
import com.sgcc.ln.pmos.common.http.HttpRequestUtils;
import com.sgcc.ln.pmos.common.http.MvpNetCallback;
import com.sgcc.ln.pmos.common.utils.ListPageUtil;
import com.sgcc.ln.pmos.e_ln_home.bean.BasicInformationEnterpriseBean;
import com.sgcc.ln.pmos.e_ln_home.bean.DCJZXXBean;
import com.sgcc.ln.pmos.e_ln_home.bean.IformenCodeBean;
import com.sgcc.ln.pmos.e_ln_home.contract.BasicInformationEnterpriseContract;
import com.sgcc.ln.pmos.e_ln_home.contract.DCJZXXContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class DCJZXXPresenter extends BasePresenter<DCJZXXContract.View>
        implements DCJZXXContract.Presenter {
    @Override
    public void getData(int pageNum, String applyId, boolean isloading) {
        Map<String, Object> params = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        data.put("applyId", applyId);
        params.put("data", data);
        Map<String, Object> pageInfo = new HashMap<>();
        String pageSizes1[] = {"20", "50", "100", "200", "500", "1000"};
        int pageSizes[] = {20, 50, 100, 200, 500, 1000};
        pageInfo.put("pageSizes1", pageSizes1);
        pageInfo.put("pageSizes", pageSizes);
        pageInfo.put("pageSize", 20);
        pageInfo.put("pageNum", new ListPageUtil(pageNum, ListPageUtil.pageSize2).getTotalPage());
        params.put("pageInfo", pageInfo);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.INFORMATION_DISCLOSURE_GETBYAPPLYID, new MvpNetCallback<DCJZXXBean>(getView(), isloading) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().getDataFailed();
            }

            @Override
            public void onResponse(DCJZXXBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if ("0".equals(response.getStatus())) {
                        if (response.getData() != null) {
                            getView().getDataSuccess(response);
                        }
                    } else {
                        if (!TextUtils.isEmpty(response.getMessage())) {
                            ToastUtils.showShort(response.getMessage());
                        }
                    }
                }
            }
        });
    }

    @Override
    public void uniformencode() {
        Map<String, Object> params = new HashMap<>();
        params.put("optType", "SELECT");
        Map<String, Object> codeInfo = new HashMap<>();
        codeInfo.put("encodeValue", "电压等级");
        params.put("codeInfo", codeInfo);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.INFORMATION_DISCLOSURE_UNIFORMENCODE, new MvpNetCallback<IformenCodeBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().uniformencodeFailed();
            }

            @Override
            public void onResponse(IformenCodeBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                if (response != null) {
                    if ("0".equals(response.getStatus())) {
                        if (response.getData() != null) {
                            getView().uniformencodeSuccess(response);
                        }
                    } else {
                        if (!TextUtils.isEmpty(response.getMessage())) {
                            ToastUtils.showShort(response.getMessage());
                        }
                    }
                }
            }
        });
    }
}
